-- init_voucher_inventory.lua
-- KEYS[1]: voucher inventory key (voucher:inventory:{voucherId})
-- ARGV[1]: total quantity
-- ARGV[2]: claimed quantity

local voucherInventoryKey = KEYS[1]
local totalQuantity = tonumber(ARGV[1])
local claimedQuantity = tonumber(ARGV[2])

local availableQuantity = totalQuantity - claimedQuantity

-- Set the available inventory
redis.call('SET', voucherInventoryKey, availableQuantity)

-- Set expiration (optional, for cleanup - 30 days)
redis.call('EXPIRE', voucherInventoryKey, 86400 * 30)

return availableQuantity